package com.mall.market.controller;

import com.mall.commons.utils.CommonResult;
import com.mall.market.service.SmsHomeAdvertiseService;
import com.mall.model.domain.SmsHomeAdvertise;
import com.mall.model.dto.SmsHomeAdvertiseDto;
import com.mall.model.vo.CommonPage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/home/advertise")
public class SmsHomeAdvertiseController {
    @Autowired
    private SmsHomeAdvertiseService smsHomeAdvertiseService;

    /**
     * 分页查询
     *
     * @param dto
     * @return
     */
    @GetMapping("/list")
    public CommonResult list(SmsHomeAdvertiseDto dto) {
        CommonPage commonPage = smsHomeAdvertiseService.list(dto);
        return CommonResult.success(commonPage);
    }

    //增
    @PostMapping("/create")
    public CommonResult create(@RequestBody SmsHomeAdvertise smsHomeAdvertise) {
        smsHomeAdvertiseService.create(smsHomeAdvertise);
        return CommonResult.success(1);
    }

    //删
    @PostMapping("/delete")
    public CommonResult delete(@RequestParam List ids) {
        log.info("需要删除的ids为：{}", ids.toString());
        smsHomeAdvertiseService.delete(ids);
        return CommonResult.success(1);
    }

    //修改状态
    @PostMapping("/update/status/{id}")
    public CommonResult updateStatus(@RequestParam Integer id, Integer recommendStatus) {
        smsHomeAdvertiseService.updateStatus(id, recommendStatus);
        return CommonResult.success("修改成功");
    }

    //修改广告内容
    @PostMapping("/update/{id}")
    public CommonResult updateContent(@RequestBody SmsHomeAdvertise smsHomeAdvertise) {
        smsHomeAdvertiseService.update(smsHomeAdvertise);
        return CommonResult.success("修改成功");
    }

    /**
     * 获取广告详情
     */
    @GetMapping("{id}")
    public CommonResult getAdvertiseInfo(@PathVariable("id") Integer id) {
        log.info("id:{}", id);
        SmsHomeAdvertise smsHomeAdvertise = smsHomeAdvertiseService.getAdvertiseInfo(id);
        return CommonResult.success(smsHomeAdvertise);
    }
}
